package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     *  回顾：在springmvc中需要配置一个内部资源视图解析器：InternalResourceViewResolver
     *      prefix : 前缀     /WEB-INF/views
     *      suffix ：后缀     .jsp
     *      寻找JSP路径： prefix + viewName + suffix
     * @return  视图名称
     */
    @GetMapping("/item/{spuId}.html")
    public String toGoodsDetailPage(Model model, @PathVariable("spuId") Long spuId) {
        Map<String, Object> itemData = pageService.loadSpuData(spuId);
        model.addAllAttributes(itemData);
        return "item";
    }
}